﻿@using PagedList.Mvc
@model PagedList.IPagedList<CubicFWNet.Data.ViewModal.InventoryChangeView>
@{
    ViewBag.Title = "调库记录";
    var start = ViewBag.Start;
    var end = ViewBag.End;
    var name = ViewBag.Name;
}
<section class="content-header">
    <h1>
        调库记录
    </h1>
    <ol class="breadcrumb">
        <li><a href="javascript:void(0);"><i class="fa fa-dashboard"></i>@Resources.Global.PageTitle</a></li>
        <li><a href="@Url.Action("Index","Home")">首页</a></li>
        <li class="active">调库记录</li>
    </ol>
</section>
<section class="content">
    <div class="form-horizontal">
        <div class="box box-solid">
            <div class="box-nav clearfix">
                <form action="@Url.Action("InventoryChangeList", "StorageTable")" method="post">
                    <div class="col-sm-12">
                        <div class="form-group col-sm-4">
                            <label class="col-sm-4 control-label no-padding-right" for=""> 开始时间 </label>
                            <div class="col-sm-8">
                                <input type="text" class="form-control datepicker" id="Start" name="Start" value="@ViewBag.Start" />
                            </div>
                        </div>
                        <div class="form-group col-sm-4">
                            <label class="col-sm-4 control-label no-padding-right" for=""> 截至时间 </label>
                            <div class="col-sm-8">
                                <input type="text" class="form-control datepicker" id="End" name="End" value="@ViewBag.End" />
                            </div>
                        </div>
                    </div>
                    <div class="col-sm-12">
                        <div class="form-group col-sm-4">
                            <label class="col-sm-4 control-label no-padding-right" for="">产品名称</label>
                            <div class="col-sm-8">
                                <input type="text" class="form-control" id="Name" name="Name" value="@ViewBag.Name" />
                            </div>
                        </div>
                        <div class="form-group col-sm-4">
                            <div class="col-sm-offset-4">
                                <div class="col-sm-8">
                                    <button type="submit" class="btn btn-primary">查询</button>
                                    <a class="btn btn-default" onclick="javascript: window.location.reload();" title="刷新"><span class="glyphicon glyphicon-refresh"></span></a>
                                </div>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
            <div class="box-body">
                <table class="footable table table-stripped table-bordered table-hover" id="footable" data-page-size="20" data-filter=#filter>
                    <thead>
                        <tr>
                            <th data-sort-ignore="true">
                                名称
                            </th>
                            <th data-sort-ignore="true">
                                数量
                            </th>
                            <th data-hide="phone,tablet" data-sort-ignore="true">
                                转出库房
                            </th>
                            <th data-hide="phone,tablet" data-sort-ignore="true">
                                转入库房
                            </th>
                            <th data-hide="phone,tablet" data-sort-ignore="true">
                                宽*长(mm)/规格
                            </th>
                            @*<th data-hide="phone,tablet" data-sort-ignore="true">
                                分类
                            </th>*@
                            <th data-hide="phone,tablet" data-sort-ignore="true">
                                调库时间
                            </th>
                            <th data-hide="phone,tablet" data-sort-ignore="true">
                                确认调库人
                            </th>
                            <th data-hide="phone,tablet" data-sort-ignore="true">
                                调库确认时间
                            </th>
                            <th data-hide="phone,tablet" data-sort-ignore="true">
                                调库状态
                            </th>
                            <th data-hide="phone,tablet" data-sort-ignore="true">
                                说明
                            </th>
                            <th data-hide="phone,tablet" data-sort-ignore="true">
                                操作
                            </th>
                        </tr>
                    </thead>
                    <tbody>
                        @if (null != Model)
                        {
                            foreach (var item in Model)
                            {
                                <tr>
                                    <td>
                                        <span onclick="ShowModal('@item.ProductId')" name="ProName" id="ProName" class="linkLayout">@Html.DisplayFor(modelItem => item.ProductName)</span>
                                    </td>
                                    <td>
                                        @item.Amount
                                    </td>
                                    <td>
                                        @Html.DisplayFor(modelItem => item.OutStorageName)
                                    </td>
                                    <td>
                                        @Html.DisplayFor(modelItem => item.InStorageName)
                                    </td>
                                    <td>
                                        @item.SizeWidth * @item.SizeLenth
                                        @if (!string.IsNullOrWhiteSpace(item.Format))
                                        {
                                            <text>/</text>@item.Format
                                        }
                                    </td>
                                    @*<td>
                                        @Html.DisplayFor(modelItem => item.ca)
                                    </td>*@
                                    <td>
                                        @Html.DisplayFor(modelItem => item.CreateTime)
                                    </td>
                                    <td>
                                        @Html.DisplayFor(modelItem => item.ConfirmName)
                                    </td>
                                    <td>
                                        @Html.DisplayFor(modelItem => item.ConfirmTime)
                                    </td>
                                    <td>
                                        @if (item.Confirm == 0)
                                        {
                                            <span class="btn-xs bg-green">未确认</span>
                                        }
                                        else if (item.Confirm == 1)
                                        {
                                            <span class="btn-xs bg-green">已确认</span>
                                        }
                                        else
                                        {
                                            <span class="btn-xs bg-green">异常</span>
                                        }
                                    </td>
                                    <td>
                                        @Html.DisplayFor(modelItem => item.Memo)
                                    </td>
                                    <td>
                                        @if (item.Confirm != 1)
                                        {
                                        }
                                            <button class="btn btn-primary btn-sm" onclick="test('@item.Id')">确认</button>
                                        <button class="btn btn-warning btn-sm" onclick="error1('@item.Id')">异常</button>
                                    </td>
                                </tr>
                            }
                        }
                    </tbody>
                    <tfoot>
                        <tr>
                            <td colspan="7">
                                每页 @Model.PageSize 条记录，共 @Model.PageCount 页，当前第 @Model.PageNumber 页
                                @Html.PagedListPager(Model, page => Url.Action("InventoryChangeList", new { page, start, name, end }))
                            </td>
                        </tr>
                    </tfoot>
                </table>
            </div>
        </div>
    </div>
</section>
@section Scripts {
    <script>
        $(document).ready(function () {
            $('#footable').footable();
        });
        //日期控件
        $(".datepicker").datepicker({
            autoclose: true,
            language: 'zh', //汉化
            format: "yyyy-mm-dd", //选择日期后，文本框显示的日期格式
            minView: "month",//选择日期后，不会再跳转去选择时分秒
        })

        function test(id) {
            layer.confirm('确认调库成功，确认后不可修改？', {
                btn: ['确认', '取消'],
                title: "确认调库"
            }, function () {
                $.ajax({
                    url: "@Url.Action("InventoryChangeConfirm", "StorageTable")",
                    type: "POST",
                    data: { id: id },
                    success: function (res) {
                    if (res != "") {
                        layer.msg(res, {
                          icon: 1,
                          time: 2000 //2秒关闭（如果不配置，默认是3秒）
                        }, function(){
                         $.reload();
                        });
                    }
                }
            });
                }, function (text, index) {
                    layer.close(index)
            });
        }

        function error1(id) {
            layer.prompt({ title: '确认调库异常？', formType: 1 }, function (pass, index) {
                layer.close(index);
                $.ajax({
                    url: "@Url.Action("InventoryChangeError", "StorageTable")",
                    type: "POST",
                    data: { id: id, memo: pass },
                    success: function (res) {
                        if (res != "") {
                            layer.msg(res, {
                                icon: 1,
                                time: 2000 //2秒关闭（如果不配置，默认是3秒）
                            }, function () {
                                $.reload();
                            });
                        }
                    }
                })
            })
        }

        //弹窗显示产品信息
        function ShowModal(id) {
            var options = {
                id: null,
                title: '产品信息',
                width: "90%",
                height: "90%",
                url: "../Product/Info?PID=" + id,
                shade: 0.3,
                btn: ['返回'],
                btnclass: ['btn btn-danger'],
                callBack: null
            }
            $.modalOpen(options);
        }
    </script>
}